package com.topnav.mc.sse;

import com.topnav.mc.admin.entity.enums.DeviceAlarmCate;
import com.topnav.mc.admin.entity.enums.EnumModal;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息推送类型
 * @Author: kenny
 * @Date: 2024/1/26 14:09
 */
public enum EnumSseMessageType {
    //1 ALARM 报警，2 DEVICE_UP_DOWN_LINE 设备上下线通知
    ALARM_NOTIFY(1,"报警通知"),
    UP_DOWN_LINE_NOTIFY(2,"设备上下线通知"),
    MEDIA_REPLAY_FINISHED(3,"设备关闭推流");;

    private int code;
    private String desc;

    private EnumSseMessageType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {return code;}

    public void setCode(int code) {this.code = code;	}

    public String getDesc() {return desc;}

    public void setDesc(String desc) {this.desc = desc;}

    public static List<EnumModal> toList(){
        List<EnumModal> list = new ArrayList<>();
        for (EnumSseMessageType enumSseMessageType : EnumSseMessageType.values()) {
            EnumModal enumModal = new EnumModal();
            enumModal.setIndex(enumSseMessageType.ordinal());
            enumModal.setCode(enumSseMessageType.getCode());
            enumModal.setName(enumSseMessageType.name());
            enumModal.setDesc(enumSseMessageType.getDesc());
            list.add(enumModal);
        }
        return list;
    }

    public static EnumSseMessageType getByCode(int code) {
        for (EnumSseMessageType entity : EnumSseMessageType.values()) {
            if (entity.getCode() == code) {
                return entity;
            }

        }
        return null;
    }

    public static String getDescByCode(int code) {
        for (EnumSseMessageType entity : EnumSseMessageType.values()) {
            if (entity.getCode() == code) {
                return entity.getDesc();
            }

        }
        return null;
    }
}
